use std::cell::RefCell;
use std::collections::HashMap;

use rjvm_vm::class_path::class_path::ClassPath;
use rjvm_vm::vm::VMParams;
use rjvm_vm::vm_class_loader::{BootstrapClassLoader, ClassLoader};

#[test]
fn vm_class_loader_test() {
    let params = VMParams {
        jdk_lib_path: "C:/Software/jdk-11.0.14+9/jmods".to_string(),
        class_path: "C:/Code/rjvm/java-example/target/classes".to_string(),
        main_class: "org/example/model/TestModel".to_string(),
    };
    let class_path_result = ClassPath::new(
        &params.jdk_lib_path, &params.class_path);
    if let Err(err) = class_path_result {
        format!("err:{}", err);
        return;
    }

    let mut class_loader = BootstrapClassLoader {
        class_path: RefCell::new(class_path_result.unwrap()),
        vm_class_cache: HashMap::new(),
    };

    let result = class_loader.load_class(&"org/example/model/TestModel".to_string());
    match result {
        Ok(cls) => {
            println!("OK")
        }
        Err(msg) => {
            println!("err:{}", msg)
        }
    };
    for (k, _) in class_loader.vm_class_cache {
        println!("k:{}", k);
    }
}